package com.inno.thread.inno.thread;
/**
 * 使用内部类创建线程
 *
 * @author May
 * @see
 * @time 2020/3/25 22:43
 */
public class InnerThreadDemo {
    private int countDown = 5;
    private InnerThread inner;

    public InnerThreadDemo(String name) {
        inner = new InnerThread(name);
    }

    private class InnerThread extends Thread{
        public InnerThread(String name) {
            super(name);
            start();
        }

        @Override
        public void run() {
            while (true) {
                System.out.println(this);
                if (--countDown == 0) {
                    return;
                }
            }
        }

        @Override
        public String toString() {
            return getName() + ":" + countDown;
        }
    }

    public static void main(String[] args) {
        new InnerThreadDemo("innerThread1");
    }
}
